博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
后台全选功能以及数据的提交方法
阅读量:4507 次
发布时间:2019-06-08

本文共 9557 字,大约阅读时间需要 31 分钟。

                  
销售品牌/厂家:
" tag="brands" />
<%--
 
--%>
 
CarByCompany.ascx
    
" tag="brands" />
CarByCompany.ascx.cs文件代码:
 public object InputID    {        set;        get;    }    protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int id = Convert.ToInt32(InputID); using (dcauto2012Entities db = new dcauto2012Entities()) { IList
list = db.Company.OrderByDescending(o => o.CompanyID) .Where(o => o.BrandID == id) .Where(o => o.ISDongChang == 0) .Where(o => o.InputID != 31) .ToList(); rptCompany.DataSource = list; rptCompany.DataBind(); } } } add.aspx.cs
using System;using System.Data;using System.Configuration;using System;using System.Collections.Generic;using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using dcauto.Utils; using EFDAL; using System.Data; using System.Data.Objects; using Webdiyer.WebControls.Mvc; using System.IO; public partial class manage_car_fourS_add : System.Web.UI.Page { int currentid; protected void Page_Load(object sender, EventArgs e) { ((manage_car_carfoursinfomaster)this.Master).txtTitle = "4S店添加"; if (!this.IsPostBack) { using (dcauto2012Entities db = new dcauto2012Entities()) { WebUtil.CtrlToList(rptbrand, db.Brand.OrderBy(o => o.ISDongChang).OrderBy(o => o.Orders).OrderBy(o => o.BrandID).Where(o => o.ISDongChang == 0).Where(s => s.InputID != 5).ToList()); } } } protected void btnSave_Click(object sender, ImageClickEventArgs e) { string[] borf = hidCarsBrand.Value.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); int flag = 0; if (borf.Length > 0) { flag = 1; } if (flag == 0) { jsHint.Alert("请选择至少一个品牌.若没有则先添加品牌后进行添加4S店"); } else { FourS model = new FourS(); model.Name = txtpname.Text; model.Adress = txtadress.Text; model.Content = txtcontent.Text; string picstr = ""; if (f1.HasFile) { string _imgpath = globalVariables.NewFileName + Path.GetExtension(f1.FileName).ToLower(); f1.PostedFile.SaveAs(globalVariables.CarsPic + _imgpath); model.Pic = _imgpath; } string picstr1 = ""; if (f2.HasFile) { picstr1 = globalVariables.NewFileName + Path.GetExtension(f2.FileName).ToLower(); f2.PostedFile.SaveAs(globalVariables.CarsPic + picstr1); model.Map = picstr1; } string picstr3 = ""; if (f3.HasFile) { picstr3 = globalVariables.NewFileName + Path.GetExtension(f3.FileName).ToLower(); f3.PostedFile.SaveAs(globalVariables.CarsPic + picstr3); model.Pic2 = picstr3; } model.Url = TextBox1.Text; model.Zip = TextBox2.Text; model.Selltel1 = TextBox3.Text; model.Selltel2 = TextBox4.Text; model.Servtel1 = TextBox5.Text; model.Servtel2 = TextBox6.Text; model.Fax = TextBox7.Text; model.Email = TextBox8.Text; model.Companyurl = txtcompanyintro.Text; model.Mapurl = txtmapurl.Text; int userid = 1; if (Session["UserId"] + "" != "") userid = int.Parse(Session["UserId"] + ""); model.Datetime = DateTime.Now; model.AddUser = Session["loginname"] + ""; model.AddUserid = userid; model.ModUser = Session["loginname"] + ""; model.ModUserid = userid; try { using (dcauto2012Entities db = new dcauto2012Entities()) { db.FourS.AddObject(model); db.SaveChanges(); var brandid = 0; foreach (string item in borf) { string witch = item.Substring(0, 1); string id = item.Replace("c", "").Replace("s", ""); EFDAL.FourSunion fs = new FourSunion(); fs.FourSid = model.FourSid; if (witch == "s") { brandid = int.Parse(id); fs.Brandid = brandid; } if (witch == "c") { fs.Brandid = brandid; fs.Companyid = int.Parse(id); db.FourSunion.AddObject(fs); db.SaveChanges(); } } } jsHint.Confirm("添加成功,是否继续添加?", "fourS.asp", "fourS_add.aspx"); } catch (Exception) { jsHint.toUrl("添加失败!", "fourS.aspx"); } } } }
编辑修改:
后台保存代码:
using System;using System.Data;using System.Configuration;using System;using System.Collections.Generic;using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using dcauto.Utils; using EFDAL; using System.Data; using System.Data.Objects; using Webdiyer.WebControls.Mvc; using System.IO; public partial class manage_car_fourS_edit : BasePage { int currentid; protected void Page_Load(object sender, EventArgs e) { ((manage_car_carfoursinfomaster)this.Master).txtTitle = "4S店修改"; if (!this.IsPostBack) { using (dcauto2012Entities db = new dcauto2012Entities()) { WebUtil.CtrlToList(rptbrand, db.Brand.OrderBy(o => o.ISDongChang).OrderBy(o => o.Orders).OrderBy(o => o.BrandID).Where(o => o.ISDongChang == 0).Where(s => s.InputID != 5).ToList()); } if (!string.IsNullOrEmpty(Request["Id"])) InitCtrl(Convert.ToInt32(int.Parse(Request["Id"]))); } } private void InitCtrl(int id) { using (dcauto2012Entities db = new dcauto2012Entities()) { currentid = id; FourS model = db.FourS.Where(s => s.FourSid == id).FirstOrDefault(); this.txtpname.Text = model.Name; this.txtadress.Text = model.Adress; this.txtcontent.Text = model.Content; TextBox1.Text = model.Url; TextBox2.Text = model.Zip; TextBox3.Text = model.Selltel1; TextBox4.Text = model.Selltel2; TextBox5.Text = model.Servtel1; TextBox6.Text = model.Servtel2; TextBox7.Text = model.Fax; TextBox8.Text = model.Email; txtcompanyintro.Text = model.Companyurl; txtmapurl.Text = model.Mapurl; if (!string.IsNullOrEmpty(model.Pic)) { this.f1error.Text = ""; } if (!string.IsNullOrEmpty(model.Map)) { this.f2error.Text = ""; } if (!string.IsNullOrEmpty(model.Pic2)) { this.f3error.Text = ""; } IList
list = db.FourSunion.Where(s => s.FourSid == id).OrderByDescending(s => s.FourSunionid).ToList(); System.Text.StringBuilder result = new System.Text.StringBuilder(); foreach (FourSunion item in list) { if (item.Companyid != null && item.Brandid != null) { result.Append("s"); result.Append(item.Brandid); result.Append(","); } if (item.Companyid != null && item.Brandid != null) { result.Append("c"); result.Append(item.Companyid); result.Append(","); } } hidCarsBrand.Value = result.ToString(); } } public void db1_Click(object sender, EventArgs e) { using (dcauto2012Entities db = new dcauto2012Entities()) { int foursid = Convert.ToInt32(Request.Params["Id"]); FourS model = db.FourS.Where(s => s.FourSid == foursid).FirstOrDefault(); model.Pic = ""; db.SaveChanges(); f1error.Text = ""; } } public void db2_Click(object sender, EventArgs e) { using (dcauto2012Entities db = new dcauto2012Entities()) { int foursid = Convert.ToInt32(Request.Params["Id"]); FourS model = db.FourS.Where(s => s.FourSid == foursid).FirstOrDefault(); model.Map = ""; db.SaveChanges(); f2error.Text = ""; } } public void db3_Click(object sender, EventArgs e) { using (dcauto2012Entities db = new dcauto2012Entities()) { int foursid = Convert.ToInt32(Request.Params["Id"]); FourS model = db.FourS.Where(s => s.FourSid == foursid).FirstOrDefault(); model.Pic2 = ""; db.SaveChanges(); f3error.Text = ""; } } protected void btnSave_Click(object sender, ImageClickEventArgs e) { using (dcauto2012Entities db = new dcauto2012Entities()) { int foursid = Convert.ToInt32(Request.Params["Id"]); FourS model = db.FourS.Where(s => s.FourSid == foursid).FirstOrDefault(); model.Name = txtpname.Text; model.Adress = txtadress.Text; model.Content = txtcontent.Text; string picstr = ""; if (f1.HasFile) { string _imgpath = globalVariables.NewFileName + Path.GetExtension(f1.FileName).ToLower(); f1.PostedFile.SaveAs(globalVariables.CarsPic + _imgpath); model.Pic = _imgpath; } string picstr1 = ""; if (f2.HasFile) { picstr1 = globalVariables.NewFileName + Path.GetExtension(f2.FileName).ToLower(); f2.PostedFile.SaveAs(globalVariables.CarsPic + picstr1); model.Map = picstr1; } string picstr3 = ""; if (f3.HasFile) { picstr3 = globalVariables.NewFileName + Path.GetExtension(f3.FileName).ToLower(); f3.PostedFile.SaveAs(globalVariables.CarsPic + picstr3); model.Pic2 = picstr3; } model.Url = TextBox1.Text; model.Zip = TextBox2.Text; model.Selltel1 = TextBox3.Text; model.Selltel2 = TextBox4.Text; model.Servtel1 = TextBox5.Text; model.Servtel2 = TextBox6.Text; model.Fax = TextBox7.Text; model.Email = TextBox8.Text; model.Companyurl = txtcompanyintro.Text; model.Mapurl = txtmapurl.Text; int userid = 1; if (Session["UserId"] + "" != "") userid = int.Parse(Session["UserId"] + ""); model.Datetime = DateTime.Now; model.AddUser = Session["loginname"] + ""; model.AddUserid = userid; model.ModUser = Session["loginname"] + ""; model.ModUserid = userid; try { db.SaveChanges(); string[] borf = hidCarsBrand.Value.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); IList
list = db.FourSunion.Where(s => s.FourSid == model.FourSid).OrderByDescending(s => s.FourSunionid).ToList(); for (int i = 0; i < list.Count; i++) { db.FourSunion.DeleteObject(list[i]); } db.SaveChanges(); var brandid = 0; foreach (string item in borf) { string witch = item.Substring(0, 1); string id = item.Replace("c", "").Replace("s", ""); EFDAL.FourSunion fs = new FourSunion(); fs.FourSid = model.FourSid; if (witch == "s") { brandid = int.Parse(id); fs.Brandid = brandid; } if (witch == "c") { fs.Brandid = brandid; fs.Companyid = int.Parse(id); db.FourSunion.AddObject(fs); db.SaveChanges(); } } jsHint.toUrl("修改成功!", "fourS.aspx?page=" + Request.QueryString["page"]); } catch (Exception) { jsHint.toUrl("修改失败!", "fourS.aspx?page=" + Request.QueryString["page"]); } } } }
 
 
 
 
 

转载于:https://www.cnblogs.com/ft-Pavilion/p/4634997.html

你可能感兴趣的文章
VS2010快捷键
查看>>
【转】CSS Nuggest
查看>>
为什么开发人员工作10多年了还会迷茫?没有安全感
查看>>
在eclipse里头用checkstyle检查项目出现 File contains tab characters (this is the first instance)原因...
查看>>
个人github链接及git学习心得总结
查看>>
c++ 计算器 带括号 代码实现
查看>>
objective -c初写
查看>>
C#中如何设置窗体的默认按钮和取消按钮
查看>>
[Swift]LeetCode276. 粉刷栅栏 $ Paint Fence
查看>>
[Swift]LeetCode351. 安卓解锁模式 $ Android Unlock Patterns
查看>>
break语句和continue语句
查看>>
python学习笔记(xlwt/xlrd下载安装)
查看>>
java代码中添加log4j日志
查看>>
Java学习不走弯路教程(19 对于Service的自动注入)
查看>>
[CSS3] :empty Selector
查看>>
webpack4 入门(二)
查看>>
LoadRunner基本简介
查看>>
编写一个模拟注册用户和验证用户登陆的程序
查看>>
jquery 左侧多级菜单 根据xml文件自动生成
查看>>
JS - CommonJS、AMD、CMD
查看>>